#include <QtGui/QApplication>
//#include "/usr/local/qserialport/include/QtSerialPort/QSerialPort"
#include "statusdisplay.h"
#include "datahandler.h"
#include "serialhandler.h"

#include <termios.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    statusDisplay w;
    dataHandler d;
    serialHandler s;

    //sending data from the data handler to the GUI
    QObject::connect(&d, SIGNAL(tipNew(char)), &w, SLOT(tipSet(char)));
    QObject::connect(&d, SIGNAL(middleNew(char)), &w, SLOT(middleSet(char)));
    QObject::connect(&d, SIGNAL(knuckleNew(char)), &w, SLOT(knuckleSet(char)));
    QObject::connect(&d, SIGNAL(sweepNew(char)), &w, SLOT(sweepSet(char)));
    QObject::connect(&d, SIGNAL(logMessage(QString)), &w, SLOT(logMessage(QString)));

    //controlling the serial handler from the GUI
    QObject::connect(&w, SIGNAL(baudSet(long)), &s, SLOT(setBaud(long)));
    QObject::connect(&w, SIGNAL(portNameSet(QString)), &s, SLOT(setPortName(QString))); //char*)), &s, SLOT(setPortName(char*)));
    QObject::connect(&w, SIGNAL(startSerial()), &s, SLOT(openSerial()));
    QObject::connect(&w, SIGNAL(stopSerial()), &s, SLOT(closeSerial()));

    //passing data from serial handler to data handler
    QObject::connect(&s, SIGNAL(serialBytes(QByteArray)), &d, SLOT(serialData(QByteArray)));

    //serial status messages from serial handler to status display
    QObject::connect(&s, SIGNAL(logMessage(QString)), &w, SLOT(logMessage(QString)));
    QObject::connect(&s, SIGNAL(serialFailure()), &w, SLOT(serialfailure()));
    //and actually go
    w.show();



    return a.exec();
}
